package ThreadPool.lagou.concurrent.demo05;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 通过中断标记位中断线程
 * @date 2022/5/25 21:36
 */
public class MyThread extends Thread{

    private boolean flag = true;

    @Override
    public void run() {
        while(flag){
            System.out.println("线程正在执行");
            try {
                sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public void stopRuning(){
        this.flag = false;
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        myThread.start();
        sleep(5000);
        myThread.stopRuning();
        // 这里是为了让主线程进行等待
        myThread.join();
    }
}

